import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:dio_log/interceptor/dio_log_interceptor.dart';
import 'package:flutter_gex_news/model/MovieModel.dart';
typedef Scuccess = void Function(int statuscode,String message,dynamic json);
typedef Failure =  void Function(int statuscode);

class ApiService{

   static Future<List<MovieModel>?> fetchMovies({required Scuccess scuess,required Failure failure}) async{
     var dio = Dio();
     var response = await dio.get("http://apis.juhe.cn/fapig/douyin/billboard?type=hot_video&size=50&key=9eb8ac7020d9bea6048db1f4c6b6d028");
     dio.interceptors.add(DioLogInterceptor());

     if(response.statusCode == 200){
       if(scuess!= null){
         // scuess(response.statusCode,response.statusMessage,json.decode(response.data.toString()));
       }
       String jsonString = response.data['result'];
        return movieModelFromJson(json.decode(jsonString));
     }else{
       // failure(response.statusCode);
     }
   }
}
